<?php
class Gestff_AuthController extends Zend_Controller_Action
{
   
    private $coordinateur;
    
    public function init(){
     	$this->_helper->layout()->disableLayout();
    	$this->_helper->layout()->setLayout("auth");
    	
    	$coordinateur=Zend_Auth::getInstance()->getIdentity();
    	$this->coordinateur=$coordinateur;
    	if($coordinateur)
    	{
    		$this->view->isauthentifier= true;
    		
    	}else{
    		$this->view->isauthentifier= false;
    	}
    }
    public function indexAction()
    {
    
  	  echo "gestff ";
    }
    
    public function logoutAction()
    {
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->viewRenderer->setNoRender(true);
    
    	$auth = Zend_Auth::getInstance();
    	$auth->clearIdentity();
    	$this->_helper->redirector("accueil","auth","gestff");
    }
    public function loginAction()
    {
    
    	$auth = Zend_Auth::getInstance();
    	$auth->clearIdentity();
    	$this->view->title="Authentification";
    	$this->view->authform=$auth;
    }
    public function accueilAction(){
    
    	if ($this->_request->isPost())
    	{
    		$formData = $this->_request->getPost();
    		$DbAdapter=Zend_Db_Table::getDefaultAdapter();
    		$authAdapter = new Zend_Auth_Adapter_DbTable($DbAdapter);
    		$authAdapter->setTableName('participant');
    		$authAdapter->setIdentityColumn('login');
    		$authAdapter->setCredentialColumn('password');
    		// Set the input credential values to authenticate against
    		$authAdapter->setIdentity($formData["inputEmail"]);
    		$authAdapter->setCredential($formData["inputPassword"]);
    		// print_r($formData);die();
    		// do the authentication
    		$auth = Zend_Auth::getInstance();
    
    		$result = $auth->authenticate($authAdapter);
    
    		if ($result->isValid()) {
    			// success: store database row to auth's storage
    			// system. (Not the password though!)
    			$data = $authAdapter->getResultRowObject(null, 'password');
    			//print_r($data);die();
    			$auth->getStorage()->write($data);
    			// Zend_Session::setOptions(array('userid'=>$data->idpersonnes));
    			$this->_helper->redirector("affichage","coordinateur","gestff");
    		} else {
    			$this->_helper->redirector("accueil","auth","gestff");
    			$this->view->message = 'Login failed.';
    		}
    	}
 

	}

}